using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;

namespace MappingGenerator
{
    public class TableInfo
    {
        public List<ColumInfo> Columns = new List<ColumInfo>();
        public string Name;
        
        private ColumInfo _keyColumn;
        public ColumInfo KeyColumn
        {
            get
            {
                if (null == _keyColumn)
                {
                    if(null==Columns) throw new InvalidOperationException("No columns defined.");
                    _keyColumn = Columns.FirstOrDefault(x => x.PrimaryKey);
                    if(_keyColumn==null) throw new InvalidOperationException("Prmary key not defined");
                }
                return _keyColumn;
            }
            
        }
    }
 
}